GBML manual / Collision

tile_ground_y

Where the ground is in one column of the room: the y of the first solid pixel at or below y in the column at x, or -1 if there is none all the way down. It follows slopes pixel by pixel, so it is the height of a ramp at that x.

Syntax

tile_ground_y(x, y) -> int

Arguments

NameType
xreal
yreal

Returns

int

Description

Where the ground is in one column of the room. It looks down from y in the column at x and gives back the y of the first solid pixel it finds, or -1 if there is none all the way down. It follows slopes pixel by pixel, so on a ramp it is the height of the ramp at that x.

x and y are a place in the room, counted from the room's top-left corner. y is where the search starts. Ask from above the ground, or from inside it, and the answer is the first solid pixel at or below y.

The answer is a whole number of pixels, counted from the top of the room, the same way an instance's y is.

What counts as ground

It is the same ground tile_solid means: a solid square or a low cover square, and where the square has a slope shape, only the pixels of the shape that are solid. A square that blocks nothing is skipped, and so is the open part of a slope.

The top of a One-way platform counts as ground too, but only its top: a pixel of a One-way square with another One-way pixel right above it is skipped, so asking from inside a platform finds the ground under it, not the platform you are in.

When the answer is -1

The cost is a look at one square for every 8 pixels it has to go down, then a look at the pixels of the first square that blocks.

Example

var floor_y = tile_ground_y(x, y);
if (floor_y >= 0) {
    y = floor_y - 8;
}

Puts the walker 8 pixels above the ground under it, even when that ground is a ramp. (The 8 is half the height of a 16 pixel tall walker.)

On the GBA

Ground is what tile_solid calls solid: a solid or low cover square, where its shape is solid. Squares that block nothing are skipped. A column outside the room, a room with no collision tile layer and a column with nothing solid below y all give -1. The answer is a whole pixel. The cost is a look at one square for each 8 pixels it has to go down, then a look at pixels inside the first square that blocks.

See also: tile_shapetile_solidtile_freeSlopes